package com.manage.demo.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.manage.demo.dao.model.StudentInfo;
import com.manage.demo.dao.model.ExamResults;

@Mapper
public interface ResultMapper {
	
	@Select("select term from Exam_Results order by term")
	public List<String> getTermlist();
	
	@Select("select "
			+ "a.*,b.name,b.grade,b.class_num "
			+ "from Exam_Results as a inner join student_info as b "
			+ "on a.stu_id=b.stu_id "
			+ "where "
			+ "(#{stuname}='' or b.name=#{stuname}) "
			+ "and (#{grades}='' or b.grade=#{grades}) "
			+ "and (#{classes}='' or b.class_num=#{classes}) "
			+ "and (#{semester}='' or a.term=#{semester}) "
			+ "and (#{examtype}='' or a.exam_type=#{examtype}) "
			+ "limit #{limit} "
			+ "offset #{offset}")
	public List<Map<String, Object>> getUserListByCondition(String semester, String examtype, String grades, String classes, String stuname, int limit, int offset);
	
	@Select("select "
			+ "a.*,b.name,b.grade,b.class_num "
			+ "from Exam_Results as a inner join student_info as b "
			+ "on a.stu_id=b.stu_id "
			+ "where "
			+ "(#{stuname}='' or b.name=#{stuname}) "
			+ "and (#{grades}='' or b.grade=#{grades}) "
			+ "and (#{classes}='' or b.class_num=#{classes}) "
			+ "and (#{semester}='' or a.term=#{semester}) "
			+ "and (#{examtype}='' or a.exam_type=#{examtype})")
	public List<Map<String, Object>> getAllresult(String semester, String examtype, String grades, String classes, String stuname);

	@Select("select "
			+ "count(*) as count "
			+ "from Exam_Results as a inner join student_info as b "
			+ "on a.stu_id=b.stu_id "
			+ "where "
			+ "(#{stuname}='' or b.name=#{stuname}) "
			+ "and (#{grades}='' or b.grade=#{grades}) "
			+ "and (#{classes}='' or b.class_num=#{classes}) "
			+ "and (#{semester}='' or a.term=#{semester}) "
			+ "and (#{examtype}='' or a.exam_type=#{examtype})")
	public List<Map<String, Object>> getCount(String semester, String examtype, String grades, String classes, String stuname);
	
	@Select("select * from student_info")
	public List<StudentInfo> getstudentlist();
}
